﻿@page "/document/{Level}/{Document}"
@inject NavigationManager Navigation


<div style="display: flex; align-items: center; position: fixed; top: 0; left: 0; right: 0; height: 50px; background: rgb(254, 249, 231); box-shadow: 0 0 10px rgb(254, 249, 231); padding: 0 15px; z-index: 1">
    <p>
        <span><b><a href="./document">NOI Exam Study文档</a></b></span>
        @if (File.Exists("./document/" + Level + "/" + Document + ".md"))
        {
            <span> | <a href=@("./document/" + Level)>@(Level)</a> | @(GetTitle("./document/" + Level + "/" + Document + ".md"))</span>
        }
        else
        {
            <span>未知文档</span>
        }
    </p>
</div>

<div style="padding: 50px; margin-top: 10px">
    @if (File.Exists("./document/" + Level + "/" + Document + ".md"))
    {
        <Markdown FilePath=@("./document/" + Level + "/" + Document + ".md")></Markdown>
    }
    else
    {
        <div style="display: flex; align-content: center; align-items: center; justify-content: center; position: absolute; top: 50px; left: 0; right: 0; bottom: 0; padding: 15%">
            <h2>你所查找的文档不存在</h2>
        </div>
    }
</div>

@functions
{
    [Parameter] public string? Level { get; set; }
    [Parameter] public string? Document { get; set; }
}
@code {
    string GetTitle(string path_md)
    {
        var first_line = File.ReadAllLines(path_md)[0];
        first_line = first_line.Replace("# ", "");
        return first_line;
    }
}